﻿$(function () {
    //加载下拉框 状态
    $("#status").ligerComboBox({
        width: 100,
        data: [
            { "ID": "-1", "Name": "全部" },
            { "ID": 9, "Name": "未审核" },
            { "ID": 0, "Name": "审核不通过" },
            { "ID": 1, "Name": "审核通过" },
            { "ID": 2, "Name": "验证异常" },
            { "ID": 3, "Name": "上报中" },
            { "ID": 4, "Name": "上报失败" },
            { "ID": 5, "Name": "上报成功" }
        ],
        isMultiSelect: false,
        valueField: "ID",
        textField: "Name",
        value: "-1",
        valueFieldID: 'hdnstatus',
    });
    $('#btnSearch').click(function () {
        search();
    });
    $('#btnSearch').click();
});
$(document).keyup(function (event) {
    if (event.keyCode == 13) {
        $('#btnSearch').click();
    }
});
function opennewtab(patientId, patientName) {
    window.parent.top.tab.addTabItem({ tabid: patientId, text: "卒中病历", url: "/StrokeCenter/MedicalRecords/Index?review=1&patientId=" + patientId });
}
//查询功能
function search(pageNumber) {
    var queryData = {
        name: $("#txtName").val(),
        status: $("#hdnstatus").val()
    }
    initTable(queryData, 1);
}
//显示表数据
var grid;
function initTable(queryData, pageNumber) {
    grid = $("#maingrid").ligerGrid({
        checkbox: true,
        height: '100%',
        url: '/ReportStatus/Search?ram=' + new Date().getMilliseconds(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: false,
        heightDiff: -5,
        columns: [
            { display: '就诊ID', name: 'PATIENT_ID', minWidth: 50, width: 150 },
            {
                display: '姓名', name: 'PATIENT_NAME', minWidth: 100, width: 120, render: function (row) {
                    return "<a style=\"cursor:pointer;\" onclick=\"opennewtab('" + row.PATIENT_ID + "','" + row.PATIENT_NAME + "')\" >" + row.PATIENT_NAME + "</a>";
                }
            },
            {
                display: '性别', name: 'PATIENT_SEX', minWidth: 50, width: 80,
                render: function (rowData) {
                    if (IsEmpty(rowData.PATIENT_SEX) || rowData.PATIENT_SEX == -1) return "未知";
                    if (rowData.PATIENT_SEX == "1") return "男";
                    if (rowData.PATIENT_SEX == "0") return "女";
                    return rowData.PATIENT_SEX;
                }
            },
            { display: '年龄', name: 'PATIENT_AGE', minWidth: 50, width: 80 },
            {
                display: '上报状态', name: 'Reviewers_State', minWidth: 50, width: 100,
                render: function (rowData) {
                    var value = "";
                    if (rowData.Reviewers_State == 9) {
                        value = "未审核";
                    }
                    else if (rowData.Reviewers_State == 0) {
                        value = "<a onclick=\"showMessage('" + rowData.PATIENT_ID + "')\" style=\"cursor:pointer\">审核不通过</a>";
                    }
                    else if (rowData.Reviewers_State == 1) {
                        value = "审核通过";
                    }
                    else if (rowData.Reviewers_State == 2) {
                        value = "<a onclick=\"showMessage('" + rowData.PATIENT_ID + "')\" style=\"cursor:pointer\">验证异常</a>";
                    }
                    else if (rowData.Reviewers_State == 3) {
                        value = "<a onclick='showMessage();'>上报中";
                    }
                    else if (rowData.Reviewers_State == 4) {
                        value = "<a onclick=\"showMessage('" + rowData.PATIENT_ID + "')\" style=\"cursor:pointer\">上报失败</a>";
                    }
                    else if (rowData.Reviewers_State == 5) {
                        value = "上报成功";
                    }
                    return value;
                }
            }],
        isScroll: true,
        onSuccess: function (data, grid) {
        }
    });
}
$(document).on("click", ".closeCls", function () {
    $("#btnSearch").click();
});

$("#btnReportStatus").click(function () {
    var rows = grid.getCheckedRows();
    var patientId = "";
    $(rows).each(function () {
        patientId += this.PATIENT_ID + "#";
    });
    if (patientId == "") return;
    patientId = patientId.substring(0, patientId.length - 1);
    $.ajax({
        url: "/ReportStatus/SetPatientApprovalStatus",
        type: 'post',
        data: { patientId: patientId },
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                $.ligerDialog.success("审核成功", "",
                    function () {
                        $('#btnSearch').click();
                    }, { allowClose: false });
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
});

function showMessage(pid) {
    $.ligerDialog.open({
        height: 350,
        width: 400,
        title: '上报状态信息',
        url: '/StrokeCenter/ReportStatus/Message?pid=' + pid,
        showMax: true,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        data: {}
    });
}